`
https://leetcode.cn/problems/delete-leaves-with-a-given-value/
`

/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @param {number} target
 * @return {TreeNode}
 */
var removeLeafNodes = function (root, target) {
  if (root === null) return null;
  // 二叉树递归框架
  // 如果左右子节点需要被删除，先递归删除它们
  root.left = removeLeafNodes(root.left, target);
  root.right = removeLeafNodes(root.right, target);
  // 后序遍历位置，此时节点 root 直到自己是否需要被删除
  if (root.val === target && root.left === null && root.right === null) {
    return null;
  }
  return root;
};